<template>
	<div v-loading="vLoading">
		<zk-auto-form :serviceConfig="widgetModel" ref="zkAutoForm" @saveForm="saveForm" v-if="widgetModel"></zk-auto-form>
	</div>
</template>

<script>
	import ala from 'ala'
	export default {
		data() {
			return {
				widgetModel: null,
				methodType: null,
				vLoading: false
			}
		},
		methods: {
			async init(methodType, orderId) {
				this.vLoading = true
				this.widgetModel = null
				let par = {
					id: orderId,
					type: methodType
				}
				this.methodType = methodType
				var response = await this.$ala.httpGet('api/Auto/Form', par)
				if (response) {
					this.widgetModel = response
				}
				this.vLoading = false
			},
			async saveForm(models) {
				let parameter = {
					type: this.methodType,
					model: JSON.stringify(models)
				}
				var response = await this.$ala.httpPost('api/auto/save', parameter)
				if (response) {
					this.$emit('methodDialogSave')
				}
			}
		}
	}
</script>